var value = false;
	
$(document).ready(function () {
	
	$( "input:button, input:submit" ).button();
	$( "#radio" ).buttonset();
	// 初始化
	init();
	
	// 添加键盘事件
  	$('#awb').keydown(function(event) {
  		var num = Number($('#awb').val());
  		var keycode = event.which;
  		
  		if((keycode >=48 && keycode <= 57) || (keycode >=96 && keycode <= 105)) {
  		} else if(keycode == 38 || keycode == 39){
  			$('#awb').attr('value', num + 1);
  		} else if(keycode == 37 || keycode == 40){
  			$('#awb').attr('value', num - 1);
  		} else if(keycode >= 65 && keycode <= 90) {
  			event.returnvalue = false;
  		}
	});
	
	bindKeyCloseWin();
	
	$('#serial').keydown(function(event) {
  		var num = Number($('#serial').val());
  		var keycode = event.which;
  		
  		if((keycode >=48 && keycode <= 57) || (keycode >=96 && keycode <= 105)) {
  		} else if(keycode == 38 || keycode == 39){
  			$('#serial').attr('value', num + 1);
  		} else if(keycode == 37 || keycode == 40){
  			$('#serial').attr('value', num - 1);
  		} else if(keycode >= 65 && keycode <= 90) {
  			event.returnvalue = false;
  		}
	});
});

function init() {
	$('#type').attr('value', false);
	
	// 设置默认的运单号
	setAWB();
}

function printKD(tid, session) {
	tid = tid.split(',')[0];
	
	$.get("./servlet/PrintExpress", { tid: tid, send_type: 'print', session: session, express_count: $("#express_count").val(), express_name: $("#express").val()}, function(data) {
		var error = $(data).find("error_response").find("msg").text();
		
		if(error != "") {
			alert(error);
		} 
	});
}

function sendGoods(session) {
	var online_send =$("input[type='radio']:checked").val();
	if(window.confirms('你确定要发货吗(点了发货就不能更改了哦!!!!)?')) {
		$.get("./servlet/PrintExpress", { tid: $("#tid").val(), online_send: online_send, session: session, send_type: 'send', awb: $("#awb").val(), express_name: $("#express").val()}, function(data){
			var len = $(data).find("error_response").length;
			var address = $(data).find("address").text();
			if(address != "")
				alert(address);
			for(var i = 0; i < len; i++) {
				var error = $(data).find("error_response").find("msg").text();
				if(error != "")
					alert(error);
			}
		});
	}
}

function printAndSendGoods(tid, session) {
	tid = tid.split(',')[0];
	
	$.get("./servlet/PrintExpress", { tid: tid, send_type: 'print', session: session, express_count: $("#express_count").val(), express_name: $("#express").val()}, function(data) {
		var error = $(data).find("error_response").find("msg").text();
		
		if(error == "") {
			if(window.confirm('要继续发货吗?')) {
				sendGoods();
			}
		} 
	});
}

function showAwbDescript() {
	var html = "<font size='2' color='red'>按上下键可以递增或者递减</font>";
	$("#awb_desc").html(html);
}

function confirms(str) {
	return window.confirm(str);
}

function setAWB() {
	$.get("awb.jsp", { express: $("#express").val() }, function(data) {
		$("#awb").attr("value", data);
	});
}

function selecChange() {   	 		
	setAWB();
}

function test() {
	alert(str.match('nihk')); 	 		
};